package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author : Sonic
 * @version : 1.0
 * @createTime : 2024-12-07  10:29
 * @description :
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api("OrderController Api")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * @param: [ordersPageQueryDTO]
     * @return: com.sky.result.Result<com.sky.result.PageResult>
     * @description: 条件、分页 查询订单
     **/
    @GetMapping("/conditionSearch")
    @ApiOperation("conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("###### conditionSearch");
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * @param: []
     * @return: com.sky.result.Result<com.sky.vo.OrderStatisticsVO>
     * @description: 统计2、3、4订单类型的订单数量
     **/
    @GetMapping("/statistics")
    @ApiOperation("statistics")
    public Result<OrderStatisticsVO> statistics() {
        log.info("###### statistics");
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * @param: [id]
     * @return: com.sky.result.Result<com.sky.vo.OrderVO>
     * @description: 获取订单详情
     **/
    @GetMapping("/details/{id}")
    @ApiOperation("getOrderDetailByOrderID")
    public Result<OrderVO> getOrderDetailByOrderID(@PathVariable Long id) {
        log.info("###### getOrderDetailByOrderID");
        OrderVO orderVO = orderService.getByOrderId(id);
        return Result.success(orderVO);
    }

    /**
     * @param: [ordersConfirmDTO]
     * @return: com.sky.result.Result
     * @description: 接单, 注意传参是一个 Json
     **/
    @PutMapping("/confirm")
    @ApiOperation("confirm order")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        log.info("###### confirm order");
        orderService.confirmOrder(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * @param: [ordersRejectionDTO]
     * @return: com.sky.result.Result
     * @description: 拒绝叮订单，商家需要给出拒绝理由
     **/
    @PutMapping("/rejection")
    @ApiOperation("Rejection order")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        log.info("###### Rejection order");
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * @param: [ordersCancelDTO]
     * @return: com.sky.result.Result
     * @description: 商家取消订单
     **/
    @PutMapping("/cancel")
    @ApiOperation("Cancel order")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        log.info("###### Cancel order");
        orderService.adminCancelOrder(ordersCancelDTO);
        return Result.success();
    }

    /**
     * @param: [id]
     * @return: com.sky.result.Result
     * @description: 派送订单，只需要修改订单状态
     **/
    @PutMapping("/delivery/{id}")
    @ApiOperation("Delivery order")
    public Result delivery(@PathVariable Long id) {
        log.info("###### Delivery order");
        orderService.delivery(id);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    @ApiOperation("Complete order")
    public Result complete(@PathVariable Long id) {
        log.info("###### Complete order");
        orderService.complete(id);
        return Result.success();
    }
}
